Refactor config dir to ~/.wvdsh and improve auth status#5
Conversation
Replaces use of platform-specific config directories with a unified ~/.wvdsh directory for credentials and cache. Enhances authentication logic to distinguish between environment variable and file-based credentials, updating the 'auth status' output accordingly. Also adds an AuthSource enum and removes the unused is_authenticated method.
|
@claude review this |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
|
Claude finished @franzwarning's task in 1m 22s —— View job Code Review
SummaryThis PR makes a breaking change by migrating from platform-specific config directories to a unified 🔴 Critical Issues1. Missing Migration Path for Existing Users (src/config.rs:7-10, src/auth.rs:55-68)The PR moves from platform-specific directories (managed by the Impact: Users will need to re-authenticate and may lose stored credentials without warning. Recommendation: Add migration logic that checks the old location on first use and moves credentials to the new location: pub fn wvdsh_dir() -> Result<PathBuf> {
let base_dirs = BaseDirs::new()
.ok_or_else(|| anyhow::anyhow!("Could not determine home directory"))?;
let new_dir = base_dirs.home_dir().join(".wvdsh");
// One-time migration from old location
migrate_from_old_location(&new_dir)?;
Ok(new_dir)
}
fn migrate_from_old_location(new_dir: &Path) -> Result<()> {
// Check if migration already happened
if new_dir.exists() {
return Ok(());
}
// Try to find old credentials
if let Ok(old_dirs) = ProjectDirs::from("gg", "wavedash", "cli") {
let old_creds = old_dirs.config_dir().join("credentials.json");
if old_creds.exists() {
fs::create_dir_all(new_dir)?;
fs::copy(&old_creds, new_dir.join("credentials.json"))?;
// Also migrate other files like update-cache.json, dev-server certs, etc.
}
}
Ok(())
}2. Duplicate Auth Retrieval Logic (src/auth.rs:55-86)The Issue: If credentials are deleted between the two method calls, inconsistent results may occur. Recommendation: Refactor to check once and return structured data: pub fn get_auth_info(&self) -> AuthInfo {
// Check environment first
if let Ok(api_key) = std::env::var("WVDSH_TOKEN") {
if !api_key.is_empty() {
return AuthInfo {
source: AuthSource::Environment,
api_key: Some(api_key),
};
}
}
// Check file
if let Some(api_key) = self.read_file_credentials() {
return AuthInfo {
source: AuthSource::File,
api_key: Some(api_key),
};
}
AuthInfo {
source: AuthSource::None,
api_key: None,
}
}
pub struct AuthInfo {
pub source: AuthSource,
pub api_key: Option<String>,
}🟡 Moderate Issues3. AuthSource Enum Should Derive Common Traits (src/auth.rs:13-17)The #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AuthSource {
Environment,
File,
None,
}4. Inconsistent Token Masking Logic (src/main.rs:118-123, 129-134)The token masking logic is duplicated in both the fn mask_token(token: &str) -> String {
if token.len() > 10 {
format!("{}...{}", &token[..6], &token[token.len() - 3..])
} else {
"***".to_string()
}
}5. Removal of
|
Introduced AuthInfo struct to encapsulate authentication source and API key. Refactored AuthManager to provide get_auth_info and improved API key retrieval logic. Added mask_token helper in main.rs to consistently mask tokens in status output.
Replaces use of platform-specific config directories with a unified ~/.wvdsh directory for credentials and cache. Enhances authentication logic to distinguish between environment variable and file-based credentials, updating the 'auth status' output accordingly. Also adds an AuthSource enum and removes the unused is_authenticated method.
Note
Consolidates app data under a single user dir and clarifies auth behavior.
~/.wvdsh(replaces platform-specific dirs)WVDSH_TOKENfirst, then stored file; addsAuthSourceand updatesauth statusmessaging with masked tokenis_authenticatedmethod~/.wvdsh/dev-serverand updater cache path accordingly0.1.47Written by Cursor Bugbot for commit c3bd970. This will update automatically on new commits. Configure here.